package biolean;

import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.swing.JList;
import javax.swing.ListModel;

import biolean.commands.Command;

class ToolTipList extends JList 
{
    public ToolTipList(String[] data) 
    {
	    super(data);
		addMouseMotionListener( new MouseMotionAdapter() 
		{
			public void mouseMoved( MouseEvent e) 
			{
				ToolTipList theList = (ToolTipList) e.getSource();
				ListModel model = theList.getModel();
				int index = theList.locationToIndex(e.getPoint());
				if (index > -1) {
					//theList.setToolTipText(null);

				
					try
					{
						Class<?> cls = Biolean.cmdRegister.findClass( (String) model.getElementAt(index) );
						Method method = cls.getMethod("getDescription", null );
						String text = (String)method.invoke(null, null);
						theList.setToolTipText(text);
					} catch (IllegalAccessException e1){
						e1.printStackTrace();
					} catch (IllegalArgumentException e1){
						e1.printStackTrace();
					} catch (InvocationTargetException e1){
						e1.printStackTrace();
					} catch (NoSuchMethodException e1){
						e1.printStackTrace();
					} catch (SecurityException e2){
						e2.printStackTrace();
					}

				}
			}
	});
}

    // Expose the getToolTipText event of our JList
    public String getToolTipText(MouseEvent e)
    {
        return super.getToolTipText();
    }

}